<?php
function get_os() {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        return "w";
    } else {
        return "l";
    }
}

$system = array();
$system['os'] = get_os();

if ($system['os'] == "w") {
    if (isset($_ENV['path'])) {
        $path = trim($_ENV['path']);
        @$exec = end(explode("\\", $path));
        $system['workdir'] = str_replace($exec, "", $path) . "\\notebubble\\";
    } else {
        $system['workdir'] = "c:\\notebubble\\";
    }
    if (!is_dir($system['workdir'])) {
        mkdir($system['workdir']);
    }
    if (!file_exists($system['workdir'] . "settings.php")) {
        $settings['timezone'] = 'America/Mexico_City';
        $settings['locale'] = "english";
        $settings['locale_not_set'] = "true";
        file_put_contents($system['workdir'] . "settings.php", "<?php\r\n" . '$settings = ' . var_export($settings, true) . ";");
        $db = file_get_contents("_templatedatabase.db");
        file_put_contents($system['workdir'] . "database.db", $db);
        $system['first_run'] = "yes";
    }
    include $system['workdir'] . "settings.php";
    $settings['path'] = (isset($settings['path']) ? $settings['path'] : $system['workdir']);
} else {
    $home_dir = posix_getpwnam(get_current_user()) ['dir'];
    if (!is_dir("$home_dir/.local/share/notebubble/")) {
        mkdir("$home_dir/.local/share/notebubble/");
    }

    $system['workdir'] = "$home_dir/.local/share/notebubble/";
    if (!file_exists($system['workdir']."settings.php")) {
        $settings['path'] = $system['workdir'];
        $settings['timezone'] = 'America/Mexico_City';
        $settings['locale'] = "english";
        $settings['locale_not_set'] = "true";
        file_put_contents($system['workdir']."settings.php", "<?php\r\n" . '$settings = ' . var_export($settings, true) . ";");
        $db = file_get_contents("_templatedatabase.db");
        file_put_contents($system['workdir']."database.db", $db);
        $system['first_run'] = "yes";
    }
    include $system['workdir']."settings.php";
}

if (!isset($settings['timezone'])) {
    $settings['timezone'] = 'America/Mexico_City';
}
include "languages/" . $settings['locale'] . ".php";
$system['colors'] = array("#2980B9", "#F39C12", "#27AE60", "#8E44AD", "#E74C3C", "#E57399");
?>
